package com.host.dyyl.utils;

import android.content.Context;
import android.text.TextUtils;


import com.mynet.GlobalHttp;
import com.mynet.OkHttpException;
import com.mynet.okhttp.listener.RequestListener;

import okhttp3.Headers;


/**
 * Created by  on 2017/5/9.
 */

public class ProjectHttp extends GlobalHttp {

    protected static final String CODE = "code";
    protected static final String MSG = "err_desc";

    public ProjectHttp(Context context) {
        super(context);
    }

    @Override
    protected <T> void analyJson(String result, int code, Headers headers, RequestListener<T> requestListener) {
        try {
            if (!TextUtils.isEmpty(result)) {
                requestListener.onSuccess((T) result, code, headers);
            } else {
                requestListener.onFailure(new OkHttpException(code, OkHttpException.JSON_ERROR_MSG));
            }
        } catch (Exception e) {
            requestListener.onFailure(new OkHttpException(OkHttpException.OTHER_ERROR, e.getMessage()));
        }
    }

}
